<template>
	<view class="body">
		<xk-header title="设备维修"></xk-header>
		<view class="list" >
			<view class="list-item header" @click="orderMore = !orderMore">
				<view>维修单号:  {{data.apply_no}}</view>
				<image v-if="!orderMore" src="/static/up.png"></image>
				<image v-else  src="/static/down.png"></image>
			</view>
			<view v-if="orderMore" class="data-item">
				<view class="order-info">
					<view class="info-item">
						<view class="key">设备信息：</view>
						<text style="word-break:break-all;">{{data.device_code}}-{{data.device_name}}</text>
					</view>
					<view class="info-item"><view class="key">故障描述：</view>{{data.repair_content}}</view>
					<view class="info-item"><view class="key">设备地址：</view>{{data.address || '-'}}</view>
					<view v-if="data.apply_image" class="info-item"><view class="key"></view>
						<image-list :pics="data.apply_image"></image-list>
					</view>
				</view>
			</view>
		</view>
		<view class="list">
			<view class="list-item header">
				<view>申请取消</view>
			</view>
			<view>
				<view class="list-item textarea">
					<view>取消原因<text class="com-req"></text>：</view>
					<textarea v-model="formData.cancel_remark" placeholder="请输入取消原因" placeholder-class="placeholder"/>
				</view>
			</view>
		</view>
		<view class="common-bottom-view">
			<view class="common-btn"   @click="cancelApply">取消申请</view>
		</view>
		<view class="common-zw"></view>
	</view>
</template>

<script>
	import moment from 'moment'
	export default {
		data() {
			return {
				data: {},
				orderMore: true,
				formData: {
					repair_id: '',
					cancel_remark: '',
				}
			};
		},
		onLoad(options) {
			this.formData.repair_id = options.repairId
			this.getData();
		},
		methods:{
			getData(){
				this.$api.baseData_getPdDeviceRepair(this.formData.repair_id).then((res)=>{
					this.data = res.task
				})
			},
			initInfo() {
				if(this.isMaster){
					this.$api.baseData_getRepairWorkerList().then(res => {
						console.warn("维修人员列表：", res)
						this.users = res
					})
				}
			},
			userChange(e) {
				this.userIndex = e.detail.value;
				this.receiverId = this.users[this.userIndex].user_id
			},
			dealTimeChange(e){
				this.planTime = moment(e.dt).format('YYYY-MM-DD HH:mm')
			},

			onDispatch() {
				if (!this.receiverId) {
					this.$util.toast("请选择指定人员")
					return
				}
				if (!this.planTime) {
					this.$util.toast("请选择按排上门时间")
					return
				}

				this.$util.confirm({
					content: "确定给 '"+this.users[this.userIndex].user_name+"' 进行接单操作？",
					confirmText: "派单"
				}).then(isConfirm => {
					if (isConfirm) {
						this.$util.post({
							url: "app/pmServiceRepair/dispatch",
							data: {
								repair_id: this.data.repair_id,
								receiver_id: this.receiverId,	// 指定人员ID
								plan_date: this.planTime	// 按排上门时间
							}
						}).then(res => {
							uni.$emit('refreshHomeDataList')
							uni.$emit('refreshDeviceRepair')
							uni.redirectTo({
								url: '/pagesA/facility-repair/facility-repair-finish?type=accept'
							})
						})

					}
				})
			},
			cancelApply(){
				if (!this.formData.cancel_remark) {
					this.$util.toast("请输入取消申请原因")
					return
				}
				this.$util.confirm({
					content: "确定要取消当前维修申请？",
					confirmText: "确定"
				}).then(isConfirm => {
					if (isConfirm) {
						this.$util.post({
							url: "app/pdDeviceRepair/cancel",
							data: this.formData
						}).then(res => {
							console.log('22=========refreshPatrolTask')
							uni.$emit('refreshDeviceRepair')
							uni.$emit('refreshHomeDataList')
							uni.redirectTo({
								url: '/pagesA/facility-fix/facility-fix-finish?type=cancel'
							})
						})
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
@import '@/common/from.scss';
</style>
